<?php

/**
 * register actions.
 *
 * @package    travelbug
 * @subpackage register
 * @author     David J. Sloan
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $gedit
 * 
 */
class registerActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    if (!$this->getUser()->hasAttribute('referrer'))
	{
  		$this->getUser()->setAttribute('referrer', $this->getRequest()->getReferer());
  	}
	$form = $this->form = new OperatorForm();
	//$this->form = new ContactForm();
  }
  
  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));

     $user = new sfGuardUser();
	 $user->setUsername($this->getRequestParameter('sf_guard_user[username]'));
	 $user->setPassword($this->getRequestParameter('sf_guard_user[password]'));
	 $user->setIsActive(true);
	 $user->save();
	 
	 $profile = new sfGuardUserProfile();
     $profile->setsfGuardUser($user);
	 $profile->setFirstname($this->getRequestParameter('sf_guard_user[first_name]'));
	 $profile->setLastname($this->getRequestParameter('sf_guard_user[last_name]'));
	 $profile->setEmail($this->getRequestParameter('sf_guard_user[email]'));
	 $profile->setCompany($this->getRequestParameter('sf_guard_user[company]'));
	 $profile->setAddress($this->getRequestParameter('sf_guard_user[address]'));
	 $profile->setAddress2($this->getRequestParameter('sf_guard_user[address2]'));
	 $profile->setCountry($this->getRequestParameter('sf_guard_user[country]'));
	 $profile->setCity($this->getRequestParameter('sf_guard_user[city]'));
	 $profile->setState($this->getRequestParameter('sf_guard_user[state]'));
	 $profile->setZip($this->getRequestParameter('sf_guard_user[zip]'));
	 $profile->setPhone($this->getRequestParameter('sf_guard_user[phone]'));
	 $profile->setUsertype($this->getRequestParameter('user_type'));
	 $profile->save();
  }
  
  public function executeVerify(sfWebRequest $request)
  { 
  	$this->param=$this->getRequestParameter('param');
  	
  	$c = new Criteria();
  	$c->add(sfGuardUserPeer::USERNAME,$this->param);
  	$result=sfGuardUserPeer::doCount($c);
  	
  	if ($result!=0){
  		return $this->renderPartial('checkNo');
  	} else {
  		return $this->renderPartial('checkYes');
  	}
  }
  
  public function executeVerifyEmail(sfWebRequest $request)
  { 
  	$this->param=$this->getRequestParameter('param');
  	
 // 	$c = new Criteria();
 // 	$c->add(sfGuardUserPeer::USERNAME,$this->param);
 // 	$result=sfGuardUserPeer::doCount($c);
    
  	$result=stripos($this->param,"@");
  	$result1=stripos($this->param,".");
  	//echo $result;
  	//$result=1;
  	$finalResult=$result+$result1;
  	if ($result==0||$result1==0){
  		//return $this->renderText($finalResult);
  		return $this->renderPartial('checkNo');
  	} else {
  		//return $this->renderText($finalResult);
  		return $this->renderPartial('checkYes');
  	}
  }
}
